import { io } from 'socket.io-client'
export const useWorkPlace = () => {
  const URL = 'http://localhost:9000'
  const socket: any = io(URL)
  const sendText = ref()
  const sendMessageArr: any = ref([])

  const createOrJoinRoom = () => {
    socket.emit('join', { roomId: 1, name: 'test' })
  }
  createOrJoinRoom()
  /**监听发送的消息 */
  socket.on('newMessage', (e: any) => {
    console.log('监听发送的信息', e)
    sendMessageArr.value.push(e)
  })

  /**发送信息 */
  const handleSend = () => {
    socket.emit('newMessage', {
      roomId: 1,
      name: 'test',
      message: sendText.value,
    })
  }

  return {
    sendText,
    sendMessageArr,
    createOrJoinRoom,
    handleSend,
  }
}
